<!DOCTYPE html>



  


<html class="theme-next pisces use-motion" lang="">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/blog/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/blog/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/blog/css/main.css?v=5.1.4" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/blog/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/blog/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/blog/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/blog/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="Hexo, NexT" />










<meta name="description" content="工具类">
<meta name="keywords" content="Android、iOS、Web、React Native">
<meta property="og:type" content="article">
<meta property="og:title" content="Java-身份证验证(IdCardVerification)">
<meta property="og:url" content="http://yoursite.com/blog/2018/08/06/Java-Special-Function/Java-身份证验证(IdCardVerification)/index.html">
<meta property="og:site_name" content="凌浩雨_博客">
<meta property="og:description" content="工具类">
<meta property="og:locale" content="default">
<meta property="og:updated_time" content="2018-08-06T10:39:27.975Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Java-身份证验证(IdCardVerification)">
<meta name="twitter:description" content="工具类">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/blog/',
    scheme: 'Pisces',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: 'Author'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/blog/2018/08/06/Java-Special-Function/Java-身份证验证(IdCardVerification)/"/>





  <title>Java-身份证验证(IdCardVerification) | 凌浩雨_博客</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="default">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/blog/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">凌浩雨_博客</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/blog/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            Home
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/blog/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            Archives
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/blog/blog/2018/08/06/Java-Special-Function/Java-身份证验证(IdCardVerification)/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="凌浩雨">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/avatar.jpeg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="凌浩雨_博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">Java-身份证验证(IdCardVerification)</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">Posted on</span>
              
              <time title="Post created" itemprop="dateCreated datePublished" datetime="2018-08-06T18:01:39+08:00">
                2018-08-06
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <ol>
<li>工具类</li>
</ol>
<a id="more"></a>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br><span class="line">214</span><br><span class="line">215</span><br><span class="line">216</span><br><span class="line">217</span><br><span class="line">218</span><br></pre></td><td class="code"><pre><span class="line">package com.mazaiting;</span><br><span class="line"></span><br><span class="line">import java.text.ParseException;</span><br><span class="line">import java.text.SimpleDateFormat;</span><br><span class="line">import java.util.Calendar;</span><br><span class="line">import java.util.GregorianCalendar;</span><br><span class="line">import java.util.Hashtable;</span><br><span class="line">import java.util.regex.Matcher;</span><br><span class="line">import java.util.regex.Pattern;</span><br><span class="line"></span><br><span class="line">/**</span><br><span class="line"> * 身份证号码的格式：610821-20061222-612-X 由18位数字组成：前6位为地址码，第7至14位为出生日期码，第15至17位为顺序码，</span><br><span class="line"> * 第18位为校验码。检验码分别是0-10共11个数字，当检验码为“10”时，为了保证公民身份证号码18位，所以用“X”表示。虽然校验码为“X”不能更换，但若需全用数字表示，只需将18位公民身份号码转换成15位居民身份证号码，去掉第7至8位和最后1位3个数码。</span><br><span class="line"> * 当今的身份证号码有15位和18位之分。1985年我国实行居民身份证制度，当时签发的身份证号码是15位的，1999年签发的身份证由于年份的扩展（由两位变为四位）和末尾加了效验码，就成了18位。</span><br><span class="line"> * （1）前1、2位数字表示：所在省份的代码； </span><br><span class="line"> * （2）第3、4位数字表示：所在城市的代码； </span><br><span class="line"> * （3）第5、6位数字表示：所在区县的代码；</span><br><span class="line"> * （4）第7~14位数字表示：出生年、月、日； </span><br><span class="line"> * （5）第15、16位数字表示：所在地的派出所的代码； </span><br><span class="line"> * （6）第17位数字表示性别：奇数表示男性，偶数表示女性</span><br><span class="line"> * （7）第18位数字是校检码：根据一定算法生成</span><br><span class="line"> */</span><br><span class="line">public class IdCardVerification &#123;</span><br><span class="line">	/**身份证有效*/</span><br><span class="line">	public static final String VALIDITY = &quot;该身份证有效！&quot;;</span><br><span class="line">	/**位数不足*/</span><br><span class="line">	public static final String LACKDIGITS = &quot;身份证号码长度应该为15位或18位。&quot;; </span><br><span class="line">	/**最后一位应为数字*/</span><br><span class="line">	public static final String LASTOFNUMBER = &quot;身份证15位号码都应为数字 ; 18位号码除最后一位外，都应为数字。&quot;;</span><br><span class="line">	/**出生日期无效*/</span><br><span class="line">	public static final String INVALIDBIRTH = &quot;身份证出生日期无效。&quot;; </span><br><span class="line">	/**生日不在有效范围*/</span><br><span class="line">	public static final String INVALIDSCOPE = &quot;身份证生日不在有效范围。&quot;; </span><br><span class="line">	/**月份无效*/</span><br><span class="line">	public static final String INVALIDMONTH = &quot;身份证月份无效&quot;;</span><br><span class="line">	/**日期无效*/</span><br><span class="line">	public static final String INVALIDDAY = &quot;身份证日期无效&quot;;</span><br><span class="line">	/**身份证地区编码错误*/</span><br><span class="line">	public static final String CODINGERROR = &quot;身份证地区编码错误。&quot;;</span><br><span class="line">	/**身份证校验码无效*/</span><br><span class="line">	public static final String INVALIDCALIBRATION = &quot;身份证校验码无效，不是合法的身份证号码&quot;;</span><br><span class="line">	</span><br><span class="line">	/**</span><br><span class="line">	 * 检验身份证号码是否符合规范</span><br><span class="line">	 * @param IDStr 身份证号码</span><br><span class="line">	 * @return 错误信息或成功信息</span><br><span class="line">	 */</span><br><span class="line">	public static String IDCardValidate(String IDStr) throws ParseException &#123;</span><br><span class="line">		String tipInfo = VALIDITY;// 记录错误信息</span><br><span class="line">		String Ai = &quot;&quot;;</span><br><span class="line">		// 判断号码的长度 15位或18位</span><br><span class="line">		if (IDStr.length() != 15 &amp;&amp; IDStr.length() != 18) &#123;</span><br><span class="line">			tipInfo = LACKDIGITS;</span><br><span class="line">			return tipInfo;</span><br><span class="line">		&#125;</span><br><span class="line"></span><br><span class="line">		// 18位身份证前17位位数字，如果是15位的身份证则所有号码都为数字</span><br><span class="line">		if (IDStr.length() == 18) &#123;</span><br><span class="line">			Ai = IDStr.substring(0, 17);</span><br><span class="line">		&#125; else if (IDStr.length() == 15) &#123;</span><br><span class="line">			Ai = IDStr.substring(0, 6) + &quot;19&quot; + IDStr.substring(6, 15);</span><br><span class="line">		&#125;</span><br><span class="line">		if (isNumeric(Ai) == false) &#123;</span><br><span class="line">			tipInfo = LASTOFNUMBER;</span><br><span class="line">			return tipInfo;</span><br><span class="line">		&#125;</span><br><span class="line"></span><br><span class="line">		// 判断出生年月是否有效</span><br><span class="line">		String strYear = Ai.substring(6, 10);// 年份</span><br><span class="line">		String strMonth = Ai.substring(10, 12);// 月份</span><br><span class="line">		String strDay = Ai.substring(12, 14);// 日期</span><br><span class="line">		if (isDate(strYear + &quot;-&quot; + strMonth + &quot;-&quot; + strDay) == false) &#123;</span><br><span class="line">			tipInfo = INVALIDBIRTH;</span><br><span class="line">			return tipInfo;</span><br><span class="line">		&#125;</span><br><span class="line">		GregorianCalendar gc = new GregorianCalendar();</span><br><span class="line">		SimpleDateFormat s = new SimpleDateFormat(&quot;yyyy-MM-dd&quot;);</span><br><span class="line">		try &#123;</span><br><span class="line">			if ((gc.get(Calendar.YEAR) - Integer.parseInt(strYear)) &gt; 150</span><br><span class="line">					|| (gc.getTime().getTime() - s.parse(strYear + &quot;-&quot; + strMonth + &quot;-&quot; + strDay).getTime()) &lt; 0) &#123;</span><br><span class="line">				tipInfo = INVALIDSCOPE;</span><br><span class="line">				return tipInfo;</span><br><span class="line">			&#125;</span><br><span class="line">		&#125; catch (NumberFormatException e) &#123;</span><br><span class="line">			e.printStackTrace();</span><br><span class="line">		&#125; catch (java.text.ParseException e) &#123;</span><br><span class="line">			e.printStackTrace();</span><br><span class="line">		&#125;</span><br><span class="line">		if (Integer.parseInt(strMonth) &gt; 12 || Integer.parseInt(strMonth) == 0) &#123;</span><br><span class="line">			tipInfo = INVALIDMONTH;</span><br><span class="line">			return tipInfo;</span><br><span class="line">		&#125;</span><br><span class="line">		if (Integer.parseInt(strDay) &gt; 31 || Integer.parseInt(strDay) == 0) &#123;</span><br><span class="line">			tipInfo = INVALIDDAY;</span><br><span class="line">			return tipInfo;</span><br><span class="line">		&#125;</span><br><span class="line"></span><br><span class="line">		// 判断地区码是否有效</span><br><span class="line">		Hashtable&lt;String, String&gt; areacode = GetAreaCode();</span><br><span class="line">		// 如果身份证前两位的地区码不在Hashtable，则地区码有误</span><br><span class="line">		if (areacode.get(Ai.substring(0, 2)) == null) &#123;</span><br><span class="line">			tipInfo = CODINGERROR;</span><br><span class="line">			return tipInfo;</span><br><span class="line">		&#125;</span><br><span class="line"></span><br><span class="line">		if (isVarifyCode(Ai, IDStr) == false) &#123;</span><br><span class="line">			tipInfo = INVALIDCALIBRATION;</span><br><span class="line">			return tipInfo;</span><br><span class="line">		&#125;</span><br><span class="line"></span><br><span class="line">		return tipInfo;</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	/*</span><br><span class="line">	 * 判断第18位校验码是否正确 第18位校验码的计算方式： </span><br><span class="line">	 * 1. 对前17位数字本体码加权求和 公式为：S = Sum(Ai * Wi), i =</span><br><span class="line">	 * 0, ... , 16 其中Ai表示第i个位置上的身份证号码数字值，Wi表示第i位置上的加权因子，其各位对应的值依次为： 7 9 10 5 8 4</span><br><span class="line">	 * 2 1 6 3 7 9 10 5 8 4 2 </span><br><span class="line">	 * 2. 用11对计算结果取模 Y = mod(S, 11) </span><br><span class="line">	 * 3. 根据模的值得到对应的校验码</span><br><span class="line">	 * 对应关系为： Y值： 0 1 2 3 4 5 6 7 8 9 10 校验码： 1 0 X 9 8 7 6 5 4 3 2</span><br><span class="line">	 */</span><br><span class="line">	private static boolean isVarifyCode(String Ai, String IDStr) &#123;</span><br><span class="line">		String[] VarifyCode = &#123; &quot;1&quot;, &quot;0&quot;, &quot;X&quot;, &quot;9&quot;, &quot;8&quot;, &quot;7&quot;, &quot;6&quot;, &quot;5&quot;, &quot;4&quot;, &quot;3&quot;, &quot;2&quot; &#125;;</span><br><span class="line">		String[] Wi = &#123; &quot;7&quot;, &quot;9&quot;, &quot;10&quot;, &quot;5&quot;, &quot;8&quot;, &quot;4&quot;, &quot;2&quot;, &quot;1&quot;, &quot;6&quot;, &quot;3&quot;, &quot;7&quot;, &quot;9&quot;, &quot;10&quot;, &quot;5&quot;, &quot;8&quot;, &quot;4&quot;, &quot;2&quot; &#125;;</span><br><span class="line">		int sum = 0;</span><br><span class="line">		for (int i = 0; i &lt; 17; i++) &#123;</span><br><span class="line">			sum = sum + Integer.parseInt(String.valueOf(Ai.charAt(i))) * Integer.parseInt(Wi[i]);</span><br><span class="line">		&#125;</span><br><span class="line">		int modValue = sum % 11;</span><br><span class="line">		String strVerifyCode = VarifyCode[modValue];</span><br><span class="line">		Ai = Ai + strVerifyCode;</span><br><span class="line">		if (IDStr.length() == 18) &#123;</span><br><span class="line">			if (Ai.equals(IDStr) == false) &#123;</span><br><span class="line">				return false;</span><br><span class="line"></span><br><span class="line">			&#125;</span><br><span class="line">		&#125;</span><br><span class="line">		return true;</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	/**</span><br><span class="line">	 * 将所有地址编码保存在一个Hashtable中</span><br><span class="line">	 * @return Hashtable 对象</span><br><span class="line">	 */</span><br><span class="line"></span><br><span class="line">	private static Hashtable&lt;String, String&gt; GetAreaCode() &#123;</span><br><span class="line">		Hashtable&lt;String, String&gt; hashtable = new Hashtable&lt;String, String&gt;();</span><br><span class="line">		hashtable.put(&quot;11&quot;, &quot;北京&quot;);</span><br><span class="line">		hashtable.put(&quot;12&quot;, &quot;天津&quot;);</span><br><span class="line">		hashtable.put(&quot;13&quot;, &quot;河北&quot;);</span><br><span class="line">		hashtable.put(&quot;14&quot;, &quot;山西&quot;);</span><br><span class="line">		hashtable.put(&quot;15&quot;, &quot;内蒙古&quot;);</span><br><span class="line">		hashtable.put(&quot;21&quot;, &quot;辽宁&quot;);</span><br><span class="line">		hashtable.put(&quot;22&quot;, &quot;吉林&quot;);</span><br><span class="line">		hashtable.put(&quot;23&quot;, &quot;黑龙江&quot;);</span><br><span class="line">		hashtable.put(&quot;31&quot;, &quot;上海&quot;);</span><br><span class="line">		hashtable.put(&quot;32&quot;, &quot;江苏&quot;);</span><br><span class="line">		hashtable.put(&quot;33&quot;, &quot;浙江&quot;);</span><br><span class="line">		hashtable.put(&quot;34&quot;, &quot;安徽&quot;);</span><br><span class="line">		hashtable.put(&quot;35&quot;, &quot;福建&quot;);</span><br><span class="line">		hashtable.put(&quot;36&quot;, &quot;江西&quot;);</span><br><span class="line">		hashtable.put(&quot;37&quot;, &quot;山东&quot;);</span><br><span class="line">		hashtable.put(&quot;41&quot;, &quot;河南&quot;);</span><br><span class="line">		hashtable.put(&quot;42&quot;, &quot;湖北&quot;);</span><br><span class="line">		hashtable.put(&quot;43&quot;, &quot;湖南&quot;);</span><br><span class="line">		hashtable.put(&quot;44&quot;, &quot;广东&quot;);</span><br><span class="line">		hashtable.put(&quot;45&quot;, &quot;广西&quot;);</span><br><span class="line">		hashtable.put(&quot;46&quot;, &quot;海南&quot;);</span><br><span class="line">		hashtable.put(&quot;50&quot;, &quot;重庆&quot;);</span><br><span class="line">		hashtable.put(&quot;51&quot;, &quot;四川&quot;);</span><br><span class="line">		hashtable.put(&quot;52&quot;, &quot;贵州&quot;);</span><br><span class="line">		hashtable.put(&quot;53&quot;, &quot;云南&quot;);</span><br><span class="line">		hashtable.put(&quot;54&quot;, &quot;西藏&quot;);</span><br><span class="line">		hashtable.put(&quot;61&quot;, &quot;陕西&quot;);</span><br><span class="line">		hashtable.put(&quot;62&quot;, &quot;甘肃&quot;);</span><br><span class="line">		hashtable.put(&quot;63&quot;, &quot;青海&quot;);</span><br><span class="line">		hashtable.put(&quot;64&quot;, &quot;宁夏&quot;);</span><br><span class="line">		hashtable.put(&quot;65&quot;, &quot;新疆&quot;);</span><br><span class="line">		hashtable.put(&quot;71&quot;, &quot;台湾&quot;);</span><br><span class="line">		hashtable.put(&quot;81&quot;, &quot;香港&quot;);</span><br><span class="line">		hashtable.put(&quot;82&quot;, &quot;澳门&quot;);</span><br><span class="line">		hashtable.put(&quot;91&quot;, &quot;国外&quot;);</span><br><span class="line">		return hashtable;</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	/**</span><br><span class="line">	 * 判断字符串是否为数字,0-9重复0次或者多次</span><br><span class="line">	 * @param strnum</span><br><span class="line">	 * @return true, 符合; false, 不符合。</span><br><span class="line">	 */</span><br><span class="line">	private static boolean isNumeric(String strnum) &#123;</span><br><span class="line">		Pattern pattern = Pattern.compile(&quot;[0-9]*&quot;);</span><br><span class="line">		Matcher isNum = pattern.matcher(strnum);</span><br><span class="line">		if (isNum.matches()) &#123;</span><br><span class="line">			return true;</span><br><span class="line">		&#125; else &#123;</span><br><span class="line">			return false;</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	/**</span><br><span class="line">	 * 功能：判断字符串出生日期是否符合正则表达式：包括年月日，闰年、平年和每月31天、30天和闰月的28天或者29天</span><br><span class="line">	 * @param string</span><br><span class="line">	 * @return true, 符合; false, 不符合。</span><br><span class="line">	 */</span><br><span class="line">	public static boolean isDate(String strDate) &#123;</span><br><span class="line">		Pattern pattern = Pattern.compile(</span><br><span class="line">				&quot;^((\\d&#123;2&#125;(([02468][048])|([13579][26]))[\\-\\/\\s]?((((0?[13578])|(1[02]))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])))))|(\\d&#123;2&#125;(([02468][1235679])|([13579][01345789]))[\\-\\/\\s]?((((0?[13578])|(1[02]))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?((0?[1-9])|(1[0-9])|(2[0-8]))))))?$&quot;);</span><br><span class="line">		Matcher m = pattern.matcher(strDate);</span><br><span class="line">		if (m.matches()) &#123;</span><br><span class="line">			return true;</span><br><span class="line">		&#125; else &#123;</span><br><span class="line">			return false;</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<ol start="2">
<li>测试类<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">public class Test &#123;</span><br><span class="line"></span><br><span class="line">	public static void main(String[] args) throws ParseException &#123;</span><br><span class="line">		// String IdCard=&quot;61082120061222612X&quot;;</span><br><span class="line">		// 从控制端输入用户身份证</span><br><span class="line">		Scanner s = new Scanner(System.in);</span><br><span class="line">		System.out.println(&quot;请输入你的身份证号码：&quot;);</span><br><span class="line">		String IdCard = new String(s.next());</span><br><span class="line">		// 将身份证最后一位的x转换为大写，便于统一</span><br><span class="line">		IdCard = IdCard.toUpperCase();</span><br><span class="line">		System.out.println(IdCardVerification.IDCardValidate(IdCard));</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
</ol>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/blog/2018/08/06/Java-Special-Function/Java-解压缩各种格式/" rel="next" title="Java-解压缩各种格式">
                <i class="fa fa-chevron-left"></i> Java-解压缩各种格式
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/blog/2018/08/06/Java-Special-Function/Java-邮件(JavaMail)/" rel="prev" title="Java-邮件(JavaMail)">
                Java-邮件(JavaMail) <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      

      <section class="site-overview-wrap sidebar-panel sidebar-panel-active">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image"
                src="/blog/images/avatar.jpeg"
                alt="凌浩雨" />
            
              <p class="site-author-name" itemprop="name">凌浩雨</p>
              <p class="site-description motion-element" itemprop="description">专业从事于移动端开发，Android与iOS均有涉及，主做Android开发与React Native开发</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/blog/archives/">
              
                  <span class="site-state-item-count">393</span>
                  <span class="site-state-item-name">posts</span>
                </a>
              </div>
            

            

            

          </nav>

          

          

          
          

          
          

          

        </div>
      </section>

      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2018</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">凌浩雨</span>

  
</div>


  <div class="powered-by">Powered by <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a></div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">Theme &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Pisces</a> v5.1.4</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/blog/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/blog/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/blog/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/blog/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/blog/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/blog/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/blog/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/blog/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

</body>
</html>
